def validate_id(user_id):
    if len(user_id) > 8:
        return False
    for char in user_id:
        if not (char.isalnum() or char == '_'):
            return False
    return True

def validate_email(email):
    if '@' not in email or '.' not in email:
        return False
    at_index = email.index('@')
    dot_index = email.rindex('.')
    if at_index > dot_index:
        return False
    if at_index == 0 or dot_index == len(email) - 1:
        return False
    return True

def validate_id_number(id_number):
    if len(id_number) != 18:
        return False
    if not id_number[:-1].isdigit():
        return False
    return True

def get_gender(id_number):
    gender_digit = int(id_number[-2])
    return '男' if gender_digit % 2 == 1 else '女'

def validate_name(name):
    if len(name) > 4:
        return False
    for char in name:
        if not '\u4e00' <= char <= '\u9fff':
            return False
    return True

def main():
    print("欢迎使用用户注册小程序")
    user_id = input("请输入ID（长度不超过8位，只能由数字、字母、下划线组成）：")
    while not validate_id(user_id):
        print("ID格式错误，请重新输入。")
        user_id = input("请输入ID：")
    email = input("请输入EMAIL地址：")
    while not validate_email(email):
        print("EMAIL地址格式错误，请重新输入。")
        email = input("请输入EMAIL地址：")
    id_number = input("请输入身份证号：")
    while not validate_id_number(id_number):
        print("身份证号格式错误，请重新输入。")
        id_number = input("请输入身份证号：")
    name = input("请输入姓名（只能中文且不能超过4位）：")
    while not validate_name(name):
        print("姓名格式错误，请重新输入。")
        name = input("请输入姓名：")
    gender = get_gender(id_number)
    print("\n用户注册成功！以下是您的信息：")
    print(f"ID: {user_id}")
    print(f"EMAIL地址: {email}")
    print(f"身份证号: {id_number}")
    print(f"姓名: {name}")
    print(f"性别: {gender}")

if __name__ == "__main__":
    main()